package com.lanou3g.ptp.api.web.controller;

import com.lanou3g.ptp.api.entity.Student;
import com.lanou3g.ptp.api.utils.EntityUtils;
import com.lanou3g.ptp.api.utils.PtpResult;
import com.lanou3g.ptp.api.utils.PtpResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api(description = "学生接口")
@RestController
public class StudentController {

    @ApiOperation(value = "添加学生")
    @PostMapping("/student")
    public PtpResult login(Student student) {
        System.out.println(student);
        return PtpResultUtils.ok();
    }

    @ApiOperation(value = "导入学生")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "学生数据Excel")
    })
    @PostMapping("/student/import")
    public PtpResult importStudents(MultipartFile file) {
        return PtpResultUtils.ok();
    }

    @ApiOperation(value = "禁用学生")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "学生ID")
    })
    @PutMapping("/student/disable/{id}")
    public PtpResult disableStudent(@PathVariable Long id) {
        System.out.println(id);
        return PtpResultUtils.ok();
    }

    @ApiOperation(value = "启用学生")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "学生ID")
    })
    @PutMapping("/student/enable/{id}")
    public PtpResult enableStudent(@PathVariable Long id) {
        System.out.println(id);
        return PtpResultUtils.ok();
    }

    @ApiOperation(value = "通过ID获取学生")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "要获取的学生的ID", example = "1")
    })
    @GetMapping("/student/{id}")
    public PtpResult findById(@PathVariable Long id) {
        Student student = EntityUtils.random(Student.class);
        student.setId(id);
        return PtpResultUtils.ok(student);
    }

    @ApiOperation(value = "获取学生列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页数据量（建议不传）", defaultValue = "30"),
            @ApiImplicitParam(name = "keyword", value = "查询关键词"),
    })
    @GetMapping("/students")
    public PtpResult list(@RequestParam(defaultValue = "1") int page,
                          @RequestParam(defaultValue = "30") int size,
                          @RequestParam(defaultValue = "") String keyword) {
        System.out.println(page + "\t" + size + "\t" + keyword);
        List<Student> students = EntityUtils.random(Student.class, size);
        return PtpResultUtils.ok(students);
    }

}
